package ding;

import com.google.common.base.Joiner;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class SqlMakerO {


    private Map<String, String> map = new HashMap<>();

    public void set(String key, String value) {
        map.put(key, value);
    }

    public void remove(String key) {
        map.remove(key);
    }


    public String make(String tableName, Map<String, String> kv) {

        List<String> keys = new LinkedList<>();
        List<String> values = new LinkedList<>();

        for (String s : map.keySet()) {
            keys.add(s);
            String v = map.get(s);
            if (v == null) {
                values.add("NULL");
            } else {
                values.add("\"" + v + "\"");
            }
        }
        for (String s : kv.keySet()) {
            keys.add(s);
            String v = kv.get(s);
            if (v == null) {
                values.add("NULL");
            } else {
                values.add("\"" + v + "\"");
            }
        }

        String key = Joiner.on(',').join(keys);
        String value = Joiner.on(',').join(values);


        return "INSERT INTO " + tableName + " (" + key + ") VALUES(" + value + ");";

    }



}
